﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_MAINDETAIL
	/// </summary>
	public partial class COL_MAINDETAIL : BaseDAL<GSLMS.Entity.TB_COL_MAINDETAIL>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_MAINDETAIL()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_MAINDETAIL model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_COLID", model.COLID),
								new OracleParameter("P_COLBY", model.COLBY),
								new OracleParameter("P_COLJOINBY", model.COLJOINBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_COLMOD", model.COLMOD),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_STARTDATEHOUR", model.STARTDATEHOUR),
								new OracleParameter("P_STARTDATESECOND", model.STARTDATESECOND),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_ENDDATEHOUR", model.ENDDATEHOUR),
								new OracleParameter("P_ENDDATESECOND", model.ENDDATESECOND),
								new OracleParameter("P_IMPORTANCE", model.IMPORTANCE),
								new OracleParameter("P_NEXTDATE", model.NEXTDATE),
								new OracleParameter("P_COLCON", model.COLCON),
								new OracleParameter("P_PROMISEDATE", model.PROMISEDATE),
								new OracleParameter("P_PROMISEAMT", model.PROMISEAMT),
								new OracleParameter("P_ISUNWORKCOL", model.ISUNWORKCOL),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_maindetail_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_MAINDETAIL model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_COLID", model.COLID),
								new OracleParameter("P_COLBY", model.COLBY),
								new OracleParameter("P_COLJOINBY", model.COLJOINBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_COLMOD", model.COLMOD),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_STARTDATEHOUR", model.STARTDATEHOUR),
								new OracleParameter("P_STARTDATESECOND", model.STARTDATESECOND),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_ENDDATEHOUR", model.ENDDATEHOUR),
								new OracleParameter("P_ENDDATESECOND", model.ENDDATESECOND),
								new OracleParameter("P_IMPORTANCE", model.IMPORTANCE),
								new OracleParameter("P_NEXTDATE", model.NEXTDATE),
								new OracleParameter("P_COLCON", model.COLCON),
								new OracleParameter("P_PROMISEDATE", model.PROMISEDATE),
								new OracleParameter("P_PROMISEAMT", model.PROMISEAMT),
								new OracleParameter("P_ISUNWORKCOL", model.ISUNWORKCOL),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_maindetail_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_maindetail_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_MAINDETAIL DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_MAINDETAIL model = new GSLMS.Entity.TB_COL_MAINDETAIL();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["COLID"]!=null && dr["COLID"].ToString()!="")
				{
					model.COLID=OracleHelper.ToLong(dr["COLID"].ToString());
				}
				if(dr["COLBY"]!=null && dr["COLBY"].ToString()!="")
				{
					model.COLBY=dr["COLBY"].ToString();
				}
				if(dr["COLJOINBY"]!=null && dr["COLJOINBY"].ToString()!="")
				{
					model.COLJOINBY=dr["COLJOINBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["COLMOD"]!=null && dr["COLMOD"].ToString()!="")
				{
					model.COLMOD=dr["COLMOD"].ToString();
				}
				if(dr["STARTDATE"]!=null && dr["STARTDATE"].ToString()!="")
				{
					model.STARTDATE=DateTime.Parse(dr["STARTDATE"].ToString());
				}
				if(dr["STARTDATEHOUR"]!=null && dr["STARTDATEHOUR"].ToString()!="")
				{
                    model.STARTDATEHOUR = OracleHelper.ToInt(dr["STARTDATEHOUR"].ToString());
				}
				if(dr["STARTDATESECOND"]!=null && dr["STARTDATESECOND"].ToString()!="")
				{
                    model.STARTDATESECOND = OracleHelper.ToInt(dr["STARTDATESECOND"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["ENDDATEHOUR"]!=null && dr["ENDDATEHOUR"].ToString()!="")
				{
                    model.ENDDATEHOUR = OracleHelper.ToInt(dr["ENDDATEHOUR"].ToString());
				}
				if(dr["ENDDATESECOND"]!=null && dr["ENDDATESECOND"].ToString()!="")
				{
                    model.ENDDATESECOND = OracleHelper.ToInt(dr["ENDDATESECOND"].ToString());
				}
				if(dr["IMPORTANCE"]!=null && dr["IMPORTANCE"].ToString()!="")
				{
					model.IMPORTANCE=dr["IMPORTANCE"].ToString();
				}
				if(dr["NEXTDATE"]!=null && dr["NEXTDATE"].ToString()!="")
				{
					model.NEXTDATE=DateTime.Parse(dr["NEXTDATE"].ToString());
				}
				if(dr["COLCON"]!=null && dr["COLCON"].ToString()!="")
				{
					model.COLCON=dr["COLCON"].ToString();
				}
				if(dr["PROMISEDATE"]!=null && dr["PROMISEDATE"].ToString()!="")
				{
					model.PROMISEDATE=DateTime.Parse(dr["PROMISEDATE"].ToString());
				}
				if(dr["PROMISEAMT"]!=null && dr["PROMISEAMT"].ToString()!="")
				{
					model.PROMISEAMT=OracleHelper.ToDecimal(dr["PROMISEAMT"].ToString());
				}
				if(dr["ISUNWORKCOL"]!=null && dr["ISUNWORKCOL"].ToString()!="")
				{
                    model.ISUNWORKCOL = OracleHelper.ToInt(dr["ISUNWORKCOL"].ToString());
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_MAINDETAIL GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_MAINDETAIL sModel = new GSLMS.Entity.TB_COL_MAINDETAIL();
			string sql = "";
			sql = "select * from TB_COL_MAINDETAIL where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_MAINDETAIL> GetList(GSLMS.Entity.TB_COL_MAINDETAIL searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_MAINDETAIL>();
			DataTable dt = null;
			string tblName = "TB_COL_MAINDETAIL";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_MAINDETAIL model = new GSLMS.Entity.TB_COL_MAINDETAIL();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

